package model;

import java.util.Observable;

import observer.NotificationObjetOffre;


import utilitaire.Date;
import model.contrainte.Contrainte;
import model.contrainte.ListeContrainte;
import model.exception.ContrainteException;

import model.states.EtatOffre;
import model.states.EtatOffreEnAttenteDeValidation;

public class Offre extends Observable{

	private Date dateDeDepot;
	private String libelle;
	private String description;
	private ListeContrainte contrainteManager;
	private EtatOffre etatOffre;
	private String identifiant;
	
	public Offre(Date date,String li,String des,ListeContrainte listeC,String id) {
		super();
		dateDeDepot = date;
		libelle = li;
		description = des;
		contrainteManager = listeC;
		identifiant = id;
		etatOffre = new EtatOffreEnAttenteDeValidation();		
	}
	
	/**
	 * @return if the Offre is valid
	 */
	public boolean isValide(){
		return etatOffre.isValide();
	}
	
	@Override
	public boolean equals(Object o){
		if(!(o instanceof Offre)) return false;
		return ((Offre) o).identifiant==identifiant;
	}
	
	/**
	 * @param contrainte the Contrainte to add
	 * @throws ContrainteException 
	 */
	
	public void ajouterContrainte(Contrainte c) throws ContrainteException{
		contrainteManager.ajouterContrainte(c);
		notificationOffre("ajout d'une contrainte de type " +c.getTypeContrainte().toString());
	}
	/**
	 * @param contenu le contenu de la Contrainte a ajouter dont le type n'est pas defini
	 * @throws ContrainteException 
 	 */

	public void ajouterContrainte(Object[] contenu) throws ContrainteException{
		contrainteManager.ajouterContrainte(contenu);
		notificationOffre("ajout d'une contrainte de type " +contrainteManager.getCreateurContrainte().getTypeContrainte().toString());
	}
	
	/**
	 * Suppression d'une contrainte
	 * @param c la Contrainte a supprimer de ListeContrainte
	 * @throws ContrainteException
	 */
	public void supprimerContrainte(Contrainte c) throws ContrainteException{
		contrainteManager.supprimerContrainte(c);
		notificationOffre("suppression contrainte de type :"+c.getTypeContrainte().toString());
	}
	/**
	 * @return boolean
	 * @param Demandeur dont l'adequation est a verifier 
 	 */	
	public boolean isEnAdequation(Demandeur d){
		return contrainteManager.isEnAdequation(d.getContrainteManager());
	}
	/**
	 * @param etatOffre the etatOffre to set
	 */
	public void setEtatOffre(EtatOffre etatOffre) {
		this.etatOffre = etatOffre;
		notificationOffre("etat :"+getStatus());
	}
	/**
	 * @return the etatOffre
	 */
	public EtatOffre getEtatOffre() {
		return etatOffre;
	}

	/**
	 * @param contrainteManager the contrainteManager to set
	 */
	public void setContrainteManager(ListeContrainte contrainteManager) {
		this.contrainteManager = contrainteManager;
	}

	/**
	 * @return the contrainteManager
	 */
	public ListeContrainte getContrainteManager() {
		return contrainteManager;
	}

	/**
	 * @param dateDeDepot the dateDeDepot to set
	 */
	public void setDateDeDepot(Date dateDeDepot) {
		this.dateDeDepot = dateDeDepot;
	}

	/**
	 * @return the dateDeDepot
	 */
	public Date getDateDeDepot() {
		return dateDeDepot;
	}

	/**
	 * @param libelle the libelle to set
	 */
	public void setLibelle(String libelle) {
		this.libelle = libelle;
		notificationOffre("libelle : "+libelle);
	}

	/**
	 * @return the libelle
	 */
	public String getLibelle() {
		return libelle;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
		notificationOffre("description : "+description);
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param identifiant the identifiant to set
	 */
	public void setIdentifiant(String identifiant) {
		this.identifiant = identifiant;
	}

	/**
	 * @return the identifiant
	 */
	public String getIdentifiant() {
		return identifiant;
	}
	
	/**
	 * @return Etat courant de l'Offre (String)
	 */
	public String getStatus(){
		return etatOffre.getStatus();
	}
	
	/**
	 * Notification des observers lors d'un changement sur l'Offre
	 */
	public void notificationOffre(String enonce){
		setChanged();
		notifyObservers(new NotificationObjetOffre(this, enonce));
		clearChanged();
	}
	
	
}
